package com.ruoyi.rsikManage.Alarm.service.impl;

import java.util.List;

import com.ruoyi.rsikManage.Alarm.domain.TBaseAlarmsRequest;
import com.ruoyi.rsikManage.Alarm.service.ITBaseAlarmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.rsikManage.Alarm.mapper.TBaseAlarmsMapper;
import com.ruoyi.rsikManage.Alarm.domain.TBaseAlarms;

/**
 * 报警信息Service业务层处理
 *
 * @author sxygsj
 * @date 2024-12-26
 */
@Service
public class TBaseAlarmsServiceImpl implements ITBaseAlarmsService
{
    @Autowired
    private TBaseAlarmsMapper tBaseAlarmsMapper;

    /**
     * 查询报警信息
     *
     * @param idId 报警信息主键
     * @return 报警信息
     */
    @Override
    public TBaseAlarms selectTAlarmsByIdId(Long idId)
    {
        return tBaseAlarmsMapper.selectTAlarmsByIdId(idId);
    }

    /**
     * 查询报警信息列表
     *
     * @param tBaseAlarms 报警信息
     * @return 报警信息
     */
    @Override
    public List<TBaseAlarms> selectTAlarmsList(TBaseAlarms tBaseAlarms)
    {
        return tBaseAlarmsMapper.selectTAlarmsList(tBaseAlarms);
    }
    /**
     * 报警信息统计类型枚举
     */
    public enum CountType {
        DAY("日"),
        MONTH("月"),
        YEAR("年");

        private final String value;

        CountType(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public static CountType fromValue(String value) {
            for (CountType type : CountType.values()) {
                if (type.getValue().equals(value)) {
                    return type;
                }
            }
            return DAY; // Default to DAY if not found
        }
    }

    /**
     * 查询报警信息列表
     *
     * @param tBaseAlarmsRequest 报警信息请求对象
     * @return 报警信息列表
     */
    @Override
    public List<TBaseAlarms> selectTAlarmsCount(TBaseAlarmsRequest tBaseAlarmsRequest) {
        // 如果请求对象为空，则默认按日统计
        if (tBaseAlarmsRequest == null) {
            tBaseAlarmsRequest = new TBaseAlarmsRequest();
        }

        // 获取统计类型，默认为日统计
        CountType countType = CountType.fromValue(tBaseAlarmsRequest.getCountType());

        // 根据统计类型调用相应的Mapper方法
        switch (countType) {
            case YEAR:
                return tBaseAlarmsMapper.selectTAlarmsCountByYear(tBaseAlarmsRequest);
            case MONTH:
                return tBaseAlarmsMapper.selectTAlarmsCountByMonth(tBaseAlarmsRequest);
            case DAY:
            default:
                return tBaseAlarmsMapper.selectTAlarmsCountByHour(tBaseAlarmsRequest);
        }
    }



    /**
     * 新增报警信息
     *
     * @param tBaseAlarms 报警信息
     * @return 结果
     */
    @Override
    public int insertTAlarms(TBaseAlarms tBaseAlarms)
    {
        return tBaseAlarmsMapper.insertTAlarms(tBaseAlarms);
    }

    /**
     * 修改报警信息
     *
     * @param tBaseAlarms 报警信息
     * @return 结果
     */
    @Override
    public int updateTAlarms(TBaseAlarms tBaseAlarms)
    {
        return tBaseAlarmsMapper.updateTAlarms(tBaseAlarms);
    }

    /**
     * 批量删除报警信息
     *
     * @param idIds 需要删除的报警信息主键
     * @return 结果
     */
    @Override
    public int deleteTAlarmsByIdIds(Long[] idIds)
    {
        return tBaseAlarmsMapper.deleteTAlarmsByIdIds(idIds);
    }

    /**
     * 删除报警信息信息
     *
     * @param idId 报警信息主键
     * @return 结果
     */
    @Override
    public int deleteTAlarmsByIdId(Long idId)
    {
        return tBaseAlarmsMapper.deleteTAlarmsByIdId(idId);
    }
}
